package com.pig4cloud.pig.homecenter.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.pig4cloud.pig.homecenter.json.CustomHassDateDeserializer;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.IOException;
import java.sql.Timestamp;
import java.time.LocalDateTime;

/**
 * 实体数据
 *
 * @author pig
 * @date 2025-01-09 13:43:05
 */
@Data
@TableName("hass_entity_registry")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "实体数据")
public class HassEntityRegistryEntity extends Model<HassEntityRegistryEntity> {

 
	/**
	* eid
	*/
    @TableId(type = IdType.ASSIGN_ID)
    @Schema(description="eid")
    private Long eid;
 
	/**
	* configEntryId
	*/
	@JsonAlias({"config_entry_id","configEntryId"})
    @Schema(description="configEntryId")
    private String configEntryId;

	/**
	* hass创建时间
	*/
	@JsonAlias({"created_at","createdAt"})
	@JsonDeserialize(using = CustomHassDateDeserializer.class)
    @Schema(description="hass创建时间")
    private LocalDateTime createdAt;

	/**
	* 设备编号
	*/
	@JsonAlias({"device_id","deviceId"})
    @Schema(description="设备编号")
    private String deviceId;

	/**
	* hass禁用情况
	*/
	@JsonAlias({"disabled_by","disabledBy"})
    @Schema(description="hass禁用情况")
    private String disabledBy;

	/**
	* 实体编号
	*/
	@JsonAlias({"entity_id","entityId"})
    @Schema(description="实体编号")
    private String entityId;

	/**
	* 是否有实体名称
	*/
	@JsonAlias({"has_entity_name","hasEntityName"})
    @Schema(description="是否有实体名称")
    private Boolean hasEntityName;

	/**
	* 隐藏情况
	*/
	@JsonAlias({"hidden_by","hiddenBy"})
    @Schema(description="隐藏情况")
    private String hiddenBy;

	/**
	* 图标
	*/
    @Schema(description="图标")
    private String icon;

	/**
	* 实体id
	*/
    @Schema(description="实体id")
    private String id;

	/**
	* hass修改时间
	*/
	@JsonAlias({"modified_at","modifiedAt"})
	@JsonDeserialize(using = CustomHassDateDeserializer.class)
    @Schema(description="hass修改时间")
    private LocalDateTime modifiedAt;

	/**
	* 名称
	*/
    @Schema(description="名称")
    private String name;

	/**
	* 自定义名称
	*/
    @Schema(description="自定义名称")
    private String customeName;

	/**
	* 原始名称
	*/
	@JsonAlias({"original_name","originalName"})
    @Schema(description="原始名称")
    private String originalName;

	/**
	* 来源平台
	*/
    @Schema(description="来源平台")
    private String platform;

	/**
	* 解析类型
	*/
	@JsonAlias({"translation_key","translationKey"})
    @Schema(description="解析类型")
    private String translationKey;

	/**
	* 唯一编号
	*/
	@JsonAlias({"unique_id","uniqueId"})
    @Schema(description="唯一编号")
    private Object uniqueId;

	/**
	* 用户
	*/
    @Schema(description="用户")
    private Long userId;

	/**
	* 区域编号
	*/
	@JsonAlias({"area_id","areaId"})
    @Schema(description="区域编号")
    private String areaId;

	/**
	* 是否显示
	*/
    @Schema(description="是否显示")
    private Boolean visible;

	/**
	* 显示为
	*/
    @Schema(description="显示为")
    private String showAs;

	/**
	* 实体类型
	*/
    @Schema(description="实体类型")
    private String entityType;

	/**
	* 平台更新时间
	*/
	@TableField(fill = FieldFill.INSERT_UPDATE)
    @Schema(description="平台更新时间")
    private LocalDateTime updateTime;

	/**
	 * 输入选项及输入内容约束
	 */
	@JsonDeserialize(using = HassEntityRegistryEntity.CustomAny2StrDeserializer.class)
	@Schema(description="输入选项及输入内容约束")
	private String capabilities;

	@Schema(description="状态")
	private String state;

	@JsonAlias({"state_update_time","stateUpdateTime"})
	@Schema(description="状态更新时间戳")
	private Timestamp stateUpdateTime;


	@Schema(description="属性状态")
	private String attributes;

	@TableField(exist = false)
	private String deviceName;

	@TableField(exist = false)
	private String areaName;

	public static class CustomAny2StrDeserializer extends JsonDeserializer<String> {

		@Override
		public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
			JsonNode node = p.getCodec().readTree(p);

			return node.toString();
		}
	}
}
